package TUILayer;

import java.util.Scanner;
import ControlLayer.*;
import ModelLayer.*;
/**
 * Write a description of class MainMenu here.
 * 
 * @author (Group A) 
 * @version (2014.11.03)
 */
public class Menu
{
    private PersonUI personUI;
    private DVDUI dvdUI;
    private LoanUI loanUI;

    public Menu()
    {
        personUI = new PersonUI();
        dvdUI = new DVDUI();
        loanUI = new LoanUI();
    }

    public void mainMenuStart()
    {
        boolean exit=false;
        while (!exit) //! means while exit not is true (that is: false)
        {
            int choise = writeMainMenu();

            switch (choise) 
            {
                case 1: personUI.personMenuStart();
                break;
                case 2: dvdUI.dvdMenuStart();
                break;
                case 3: loanUI.loanMenuStart();
                break;
                case 4: writeEnd();
                exit = true;
                break;
            }
        }//end while
    }//end start

    private int writeMainMenu()
    {  
        int choise = 0;
        try
        {
            // creates a keyboard object to read input
            Scanner keyboard = new Scanner(System.in);
            System.out.println("\f *** MainMenu ***");
            System.out.println(" (1) Person");
            System.out.println(" (2) DVD");
            System.out.println(" (3) Loan");
            System.out.println(" (4) Exit");
            System.out.print("\n Make your choise: ");

            choise = keyboard.nextInt();
        }
        catch(Exception e)
        {
            System.out.println("ERROR!");
            writeMainMenu();
        }
        return choise;
    }

    private void pause()
    {
        Scanner keyboard = new Scanner(System.in);
        String vent = keyboard.nextLine();
    }

    private void writeEnd()
    {
        System.out.println("The system is safe to leave!");
    }    
}